/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: GodK
 * Date: 2024-07-17
 * Time: 14:59
 */
public class Main1 {
    public static int add1 = 0;
    public static int add2 = 0;
    public static int count = 0;
//    public static int sum = 0;
    public static void main(String[] args) throws InterruptedException {
        long stime = System.currentTimeMillis();
        int[] arr = new int[10000000];
        for(int i = 0;i < 10000000;i++){
            arr[i] = (int)(Math.random()*100+1);
        }

        int sum = 0;
//        int add1 = 0;
//        int add2 = 0;
        Thread t1 = new Thread(()->{
            for(int i = 1;i < 10000000;i+=2){
                //add1+=arr[i];
                count++;
            }
        });
        Thread t2 = new Thread(()->{
            try {
                t1.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            for(int i = 0;i < 10000000;i+=2){
                //add2+=arr[i];
                count++;
            }
        });
        t1.start();
        t2.start();
        //t1.join();
        t2.join();
        //sum = add1 + add2;
        //System.out.println(sum);
        System.out.println(count);
        long etime = System.currentTimeMillis();
        System.out.println("运行时间:"+(etime-stime)+"毫秒");
    }
}
